package com.cowin.sys.controller;

import com.cowin.base.annotation.LogAnnotation;
import com.cowin.base.auth.jwt.JwtUtil;
import com.cowin.base.result.Result;
import com.cowin.base.result.ResultGenerator;
import com.cowin.base.BaseController;
import com.cowin.sys.model.TmSysResource;
import com.cowin.sys.service.TmSysResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by  on 2019/09/18.
 *
 * @author CodeGenerator
 */
@Slf4j
@Api(value = "TmSysResourceController", description = "系统资源菜单控制器", tags = "TmSysResourceController", consumes = "application/json")
@RestController
@RequestMapping("/tm/sys/resource")
public class TmSysResourceController {
    @Resource
    private TmSysResourceService tmSysResourceService;

    @Resource
    private JwtUtil jwtUtil;

    @Value("${jwt.header}")
    private String tokenHeader;

    @Value("${jwt.tokenHead}")
    private String tokenHead;

    @LogAnnotation("获取登录用户菜单")
    @ApiOperation(value = "获取登录用户菜单")
    @GetMapping("/loginuser")
    public Result getResourceByLoginUser(HttpServletRequest httpServletRequest) {
        Object userId = jwtUtil.getUserId(httpServletRequest, this.tokenHeader, this.tokenHead);
        List<TmSysResource> list = tmSysResourceService.findResourceByLoginUser(Long.parseLong(userId.toString()));
        return ResultGenerator.genSuccessResult(list);
    }
}
